package program.Condition;

import program.SExpression;
import Exceptions.IllegalCoordinateException;
import Exceptions.ShootException;
import roborally.Element;
import roborally.Position;
import roborally.Robot;

/**
 * A class representing a CAN HIT ROBOT condition.
 * 
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */
public class CanHitRobot extends Condition {

	/**
	 * This method returns true if the given robot could hit another robot with its laser, otherwise it returns false.
	 */
	@Override
	public boolean execute(Robot robot) throws ShootException, IllegalCoordinateException {
		Position possiblePosition = robot.getPositionToShoot(robot.getOrientation(), robot.getPosition(), robot.getBoard());
		for (Element element: robot.getBoard().getPositionMap().get(possiblePosition)) {
			if (element instanceof Robot) 
				return true;	
		}
		return false;
	}
	
	/**
	 * This method returns the SExpression representation of can-hit-robot.
	 */
	@Override
	public SExpression toSExpression() {
		return this.makeSingletonSExpressionList("can-hit-robot");
	}
}
